<?php

class clsProduct {
	
	public function getAllYears($categoryId,$subCategoryId)
	{
		$arrYears = array();
		$sql = "SELECT distinct year FROM tbl_products_vehicle t WHERE productid='$categoryId' AND subproductid='$subCategoryId'";
		$run = mysql_query($sql);
		
		while($data = mysql_fetch_array($run))
		{
			array_push($arrYears, $data["year"]);
		}
		
		if(count($arrYears)>0)
		{
			$arrYears = array_unique($arrYears);
		}
		
		return $arrYears;
	}
	
	public function getSeriesForParticularYear($categoryId,$subCategoryId,$year)
	{
		
		$arrSeries = array();
		$sql = "SELECT distinct series FROM tbl_products_vehicle t WHERE productid='$categoryId' AND subproductid='$subCategoryId'
		 AND year='$year'";
		$run = mysql_query($sql);
	
		while($data = mysql_fetch_array($run))
		{
			array_push($arrSeries, $data["series"]);
		}
	
		if(count($arrSeries)>0)
		{
			$arrSeries = array_unique($arrSeries);
		}
	
		return $arrSeries;
	}
	
	public function getAllUnitDetails($categoryId, $subcategoryId, $year, $series)
	{
		$counter=0;
		$query="SELECT tbl_products_vehicle.id, tbl_products_vehicle.`year`,tbl_products_vehicle.`series`,tbl_products_vehicle.`title`,
		tbl_products_vehicle.`original_price`,tbl_products_vehicle.`offered_price`,tbl_products_vehicle.subproductid,
		tbl_products.`name`,
		tbl_images.`actimgpath`,tbl_images.`thumbimgpath`
		FROM
		tbl_products_vehicle INNER JOIN tbl_products ON tbl_products_vehicle.productid = tbl_products.id
		LEFT JOIN tbl_images ON tbl_products_vehicle.id = tbl_images.vehicleid
		WHERE tbl_products_vehicle.is_active='1' 
		AND tbl_products_vehicle.subproductid='$subcategoryId'
		AND tbl_products_vehicle.productid='$categoryId'
		AND tbl_products_vehicle.year='$year'
		AND tbl_products_vehicle.series='$series'
		GROUP BY
		tbl_products_vehicle.id";
		
		$sql_db=mysql_query($query);
		$arrVehicleDetails= array();
		while ($data = mysql_fetch_array($sql_db))
		{
			$subproductId = $data['subproductid'];
			
			$arrVehicleDetails[$counter]["id"] = $data['id'];
			$arrVehicleDetails[$counter]["year"] = $data['year'];
			$arrVehicleDetails[$counter]["series"] = $data['series'];
			$arrVehicleDetails[$counter]["title"] = $data['title'];
			$arrVehicleDetails[$counter]["original_price"] = $data['original_price'];
			$arrVehicleDetails[$counter]["offered_price"] = $data['offered_price'];
			$arrVehicleDetails[$counter]["name"] = $data['name'];
			$arrVehicleDetails[$counter]["actimgpath"] = "http://".$_SERVER["HTTP_HOST"].$data['actimgpath'];
			$arrVehicleDetails[$counter]["thumbimgpath"] = "http://".$_SERVER["HTTP_HOST"].$data['thumbimgpath'];
		
		
			
			$counter++;
		}
		
		return $arrVehicleDetails;
	}
	public function getVehicleDetailsById($categoryId, $subcategoryId, $year, $series, $title)
	{
		$arrVehicleData1 = array();
		$count=0;
		$query="SELECT tbl_products_vehicle.id, tbl_products_vehicle.`year`,tbl_products_vehicle.`series`,tbl_products_vehicle.`title`,
		tbl_products_vehicle.`original_price`,tbl_products_vehicle.`offered_price`,tbl_products_vehicle.subproductid,
		tbl_products.`name`,
		tbl_images.`actimgpath`,tbl_images.`thumbimgpath`,
		tbl_overview.`descp`,
		tbl_chasis.`frontsuspension`,tbl_chasis.`fronttravel`,tbl_chasis.`frontbraketype`,tbl_chasis.`fronttires`,tbl_chasis.`rearsuspension`,tbl_chasis.`reartravel`,tbl_chasis.`rearbraketype`,tbl_chasis.`reartires`,tbl_chasis.`frame`,
		tbl_dimension_capabilities.`dryweight`,tbl_dimension_capabilities.`frontrackcapacity`,tbl_dimension_capabilities.`rearrackcapacity`,tbl_dimension_capabilities.`towingcapacity`,tbl_dimension_capabilities.`fuelcapacity`,tbl_dimension_capabilities.`groundclearance`,tbl_dimension_capabilities.`machinedimension`,tbl_dimension_capabilities.`wheelbase`,
		tbl_drivetrain.`drivetrain`,tbl_drivetrain.`finaldrive`,tbl_drivetrain.`transmission`,
		tbl_engine.`enginetype`,tbl_engine.`displacement`,tbl_engine.`borestroke`,tbl_engine.`cylinders`,tbl_engine.`enginecooling`,tbl_engine.`fuelsystem`,tbl_engine.`startingsystem`,
		tbl_general.`speedmeter`,tbl_general.`techometer`,tbl_general.`odometer`,tbl_general.`lighting`,tbl_general.`colors`,tbl_general.`warranty`
		FROM
		tbl_products_vehicle INNER JOIN tbl_products ON tbl_products_vehicle.productid = tbl_products.id
		LEFT JOIN tbl_images ON tbl_products_vehicle.id = tbl_images.vehicleid
		LEFT JOIN tbl_overview ON tbl_products_vehicle.id = tbl_overview.vehicleid
		LEFT JOIN tbl_chasis ON tbl_products_vehicle.id = tbl_chasis.vehicleid
		LEFT JOIN tbl_dimension_capabilities ON tbl_products_vehicle.id = tbl_dimension_capabilities.vehicleid
		LEFT JOIN tbl_drivetrain ON tbl_products_vehicle.id = tbl_drivetrain.vehicleid
		LEFT JOIN tbl_engine ON tbl_products_vehicle.id = tbl_engine.vehicleid
		LEFT JOIN tbl_general ON tbl_products_vehicle.id = tbl_general.vehicleid
		WHERE tbl_products_vehicle.is_active='1' 
		AND tbl_products_vehicle.productid='$categoryId'
		AND tbl_products_vehicle.subproductid='$subcategoryId'
		AND tbl_products_vehicle.year='$year'
		AND tbl_products_vehicle.series='$series'
		AND tbl_products_vehicle.title = '$title'
		
		GROUP BY
		tbl_products_vehicle.id";
		$run = mysql_query($query);

		while($data = mysql_fetch_array($run))
		{
			$arrVehicleData1["id"] = stripslashes($data["id"]);
			$arrVehicleData1["year"] = stripslashes($data["year"]);
			$arrVehicleData1["series"] = stripslashes($data["series"]);
			$arrVehicleData1["title"] = stripslashes($data["title"]);
			$arrVehicleData1["original_price"] = stripslashes($data["original_price"]);
			$arrVehicleData1["offered_price"] = stripslashes($data["offered_price"]);
			$arrVehicleData1["name"] = stripslashes($data["name"]);
            $arrVehicleData1["actimgpath"] = "http://".$_SERVER["HTTP_HOST"].$data["actimgpath"];
            $arrVehicleData1["thumbimgpath"] = "http://".$_SERVER["HTTP_HOST"].$data["thumbimgpath"];
            $arrVehicleData1["descp"] = stripslashes($data["descp"]);
            $arrVehicleData1["frontsuspension"] = stripslashes($data["frontsuspension"]);
            $arrVehicleData1["fronttravel"] = stripslashes($data["fronttravel"]);
            $arrVehicleData1["frontbraketype"] = stripslashes($data["frontbraketype"]);
            $arrVehicleData1["fronttires"] = stripslashes($data["fronttires"]);
            $arrVehicleData1["rearsuspension"] = stripslashes($data["rearsuspension"]);
            $arrVehicleData1["reartravel"] = stripslashes($data["reartravel"]);
            $arrVehicleData1["rearbraketype"] = stripslashes($data["rearbraketype"]);
            $arrVehicleData1["reartires"] = stripslashes($data["reartires"]);
            $arrVehicleData1["frame"] = stripslashes($data["frame"]);
            $arrVehicleData1["dryweight"] = stripslashes($data["dryweight"]);
            $arrVehicleData1["frontrackcapacity"] = stripslashes($data["frontrackcapacity"]);
            $arrVehicleData1["rearrackcapacity"] = stripslashes($data["rearrackcapacity"]);	
			$arrVehicleData1["towingcapacity"] = stripslashes($data["towingcapacity"]); 	
			$arrVehicleData1["fuelcapacity"] = stripslashes($data["fuelcapacity"]); 	
			$arrVehicleData1["groundclearance"] = stripslashes($data["groundclearance"]);	
			$arrVehicleData1["machinedimension"] = stripslashes($data["machinedimension"]); 	
			$arrVehicleData1["wheelbase"] = stripslashes($data["wheelbase"]); 	
			$arrVehicleData1["enginetype"] = stripslashes($data["enginetype"]); 	
			$arrVehicleData1["displacement"] = stripslashes($data["displacement"]);
			$arrVehicleData1["borestroke"] = stripslashes($data["borestroke"]);
			$arrVehicleData1["cylinders"] = stripslashes($data["cylinders"]);
			$arrVehicleData1["enginecooling"] = stripslashes($data["enginecooling"]);
			$arrVehicleData1["fuelsystem"] = stripslashes($data["fuelsystem"]);
			$arrVehicleData1["startingsystem"] = stripslashes($data["startingsystem"]);
			$arrVehicleData1["drivetrain"] = stripslashes($data["drivetrain"]);
			$arrVehicleData1["finaldrive"] = stripslashes($data["finaldrive"]);
			$arrVehicleData1["transmission"] = stripslashes($data["transmission"]);
			$arrVehicleData1["speedmeter"] = stripslashes($data["speedmeter"]);
			$arrVehicleData1["techometer"] = stripslashes($data["techometer"]);
			$arrVehicleData1["odometer"] = stripslashes($data["odometer"]);
			$arrVehicleData1["lighting"] = stripslashes($data["lighting"]);
			$arrVehicleData1["colors"] = stripslashes($data["colors"]);
			$arrVehicleData1["warranty"] = stripslashes($data["warranty"]);
		}
		return $arrVehicleData1;	
	}
}

?>